package servlet.hedong;

import net.sf.json.JSONArray;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 参数传递页面
 * @author 何栋
 * @parameter
 * @return
 **/
@WebServlet(value = "/parameter")
public class ParameterPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        String state=req.getParameter("state");//邮件状态
        String time=req.getParameter("time");//邮件发送时间
        String operate=req.getParameter("operate");//操作类型
        String sendReceive=req.getParameter("sendReceive");
        req.setAttribute("operate",operate);
        req.setAttribute("state",state);
        req.setAttribute("time",time);
        req.setAttribute("sendReceive",sendReceive);
        if ("catEmailContent".equals(operate)){

            String message = new String(req.getParameter("message")/*.getBytes("ISO-8859-1"),"UTF-8"*/);
            req.setAttribute("message",message);
            req.getRequestDispatcher("jsp/hd/MessageContent.jsp").forward(req,resp);
        }else if ("update".equals(operate)){
          String messageId=  req.getParameter("messageId");//获取消息id
            req.setAttribute("messageId",messageId);//将消息ID设置到req中
            req.getRequestDispatcher("/fontMessageHome").forward(req,resp);//转发到servlet修改
        }else if ("delete".equals(operate)){
            String messageId=  req.getParameter("messageId");//获取消息id
            req.setAttribute("messageId",messageId);//将消息ID设置到req中
            req.getRequestDispatcher("/fontMessageHome").forward(req,resp);//转发到servlet删除
        } else {

            req.getRequestDispatcher("/jsp/hd/Message.jsp").forward(req, resp);

        }
    }
}
